import java.util.Random;
import java.util.Scanner;
public class PairOfDice {
	public static void main(String[] args) {
		System.out.println("If a player rolls a 1, that player loses all points for that round and the dice go to the other player.\n  If a player rolls two 1s in one roll (snake  eyes), that player loses all points earned so far in the game and loses control of the dice.\n  The player may voluntarily turn over the dice after any roll.\n  So the player must decide to either roll again (be a pig) and risk losing points, or give up the dice.");
		//create random generator
		
		Scanner scan = new Scanner(System.in);
		int playerScore= 0 , computerScore = 0, playerScoreRound = 0, computerScoreRound = 0;
		int playerRoll = 0, playerRoll2 = 0, computerRoll = 0, computerRoll2 = 0;
		String rollAgainAnswer;
		boolean rollAgain = true;
		boolean playerRolled1 , playerSnakeEyes , computerRolled;
		while( (playerScore < 100 ) && ( computerScore < 100 ) ) {
			while( (snakeEyes(playerRoll , playerRoll2) == 2 ) || (snakeEyes(playerRoll , playerRoll2) == 1 ) && rollAgain) {
			
				playerRoll = rollDice();
				playerRoll2 = rollDice();
				System.out.println("You have rolled a " + playerRoll + " and a " + playerRoll2 + ".");
				System.out.println("Roll again? (Y/n)");
				rollAgainAnswer = scan.next();
				rollAgain = (rollAgainAnswer.equals("Y") || rollAgainAnswer.equals("y"));
				playerScoreRound += ( playerRoll + playerRoll2 );
				
			}
			if(snakeEyes( playerRoll , playerRoll2 ) == 2) {
				playerScore = 0;
			}
			else if(snakeEyes( playerRoll , playerRoll2 ) == 1) {
				playerScoreRound = 0;
			}
			else {
				playerScore += playerScoreRound;
			}
		}
	}
	//generate number from 1-6
	public static int rollDice() {
		Random rng = new Random();
	    return ( rng.nextInt(6) + 1 );
	}
	//0 = no 1s, 1 = one 1, 2 = two 1s
	public static int snakeEyes(int roll1 , int roll2) {
		if( ( roll1 == 1 ) && ( roll2 == 1 ) ) {
			return 2;
		}
		else if( ( roll1 == 1 ) ^ ( roll2 == 1) ) {
			return 1;
		}
		else {
			return 0;
		}
	}
	
}